<template>
    <div>
        <table>
            <tr>
                <td>id</td>
                <td>name</td>
                <td>read</td>
                <td>commit</td>
                <td>time</td>
                <td>操作</td>
            </tr>
            <tr v-for="i in cate1" :key="i.id">
                <td>{{i.id}}</td>
                <td>{{i.name}}</td>
                <td>{{i.read}}</td>
                <td>{{i.commit}}</td>
                <td>{{i.time}}</td>
                <td>
                    <button @click="update(i.id)">修改</button>
                    <button @click="del(i.id)">删除</button>
                </td>
            </tr>
        </table>  
        <table>
            <tr>
                <td>id</td>
                <td>name</td>
                <td>read</td>
                <td>commit</td>
                <td>time</td>
                <td>操作</td>
            </tr>
            <tr v-for="i in cate2" :key="i.id">
                <td>{{i.id}}</td>
                <td>{{i.name}}</td>
                <td>{{i.read}}</td>
                <td>{{i.commit}}</td>
                <td>{{i.time}}</td>
                <td>
                    <button @click="update(i.id)">修改</button>
                    <button @click="del(i.id)">删除</button>
                </td>
            </tr>
        </table>      
    </div>    
</template>

<script>
import {get_books,update_books,del_books,get_books2} from "../axios_api/api.js"
export default {
    name:"showbooks",
    data() {
        return {
            cate1:"",
            cate2:""
        }
    },
    methods:{
        get_info1(){
            get_books().then(res=>{
                console.log(res)
                this.cate1 = res.data
            })
        },
        get_info2(){
            get_books2().then(res=>{
                console.log(res)
                this.cate2 = res.data
            })
        },
        update(id){
            this.$router.push({"path":"/updatebook"})
        },
        del(id){
            var data = {"id":id}
            del_books(data).then(res=>{
                console.log(res)
                window.location.reload()
            })
        },

    },
    created(){
        this.get_info1()
        this.get_info2()
    }
}
</script>

<style>

</style>
